﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace Maticsoft.Web.ProductInfo
{
    public partial class Add : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
                       
        }

        		protected void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtProductImage.Text.Trim().Length==0)
			{
				strErr+="ProductImage不能为空！\\n";	
			}
			if(this.txtProductType.Text.Trim().Length==0)
			{
				strErr+="ProductType不能为空！\\n";	
			}
			if(!PageValidate.IsNumber(txtSeriesId.Text))
			{
				strErr+="SeriesId格式错误！\\n";	
			}
			if(this.txtProductName.Text.Trim().Length==0)
			{
				strErr+="ProductName不能为空！\\n";	
			}
			if(this.txtProductGrade.Text.Trim().Length==0)
			{
				strErr+="ProductGrade不能为空！\\n";	
			}
			if(this.txtColor.Text.Trim().Length==0)
			{
				strErr+="Color不能为空！\\n";	
			}
			if(this.txtMaterial.Text.Trim().Length==0)
			{
				strErr+="Material不能为空！\\n";	
			}
			if(!PageValidate.IsDecimal(txtVoltage.Text))
			{
				strErr+="Voltage格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtPower.Text))
			{
				strErr+="Power格式错误！\\n";	
			}
			if(!PageValidate.IsDecimal(txtCutOut.Text))
			{
				strErr+="CutOut格式错误！\\n";	
			}
			if(!PageValidate.IsDecimal(txtSize.Text))
			{
				strErr+="Size格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtProductStock.Text))
			{
				strErr+="ProductStock格式错误！\\n";	
			}
			if(!PageValidate.IsDecimal(txtPrice.Text))
			{
				strErr+="Price格式错误！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			string ProductImage=this.txtProductImage.Text;
			string ProductType=this.txtProductType.Text;
			int SeriesId=int.Parse(this.txtSeriesId.Text);
			string ProductName=this.txtProductName.Text;
			string ProductGrade=this.txtProductGrade.Text;
			string Color=this.txtColor.Text;
			string Material=this.txtMaterial.Text;
			decimal Voltage=decimal.Parse(this.txtVoltage.Text);
			int Power=int.Parse(this.txtPower.Text);
			decimal CutOut=decimal.Parse(this.txtCutOut.Text);
			decimal Size=decimal.Parse(this.txtSize.Text);
			int ProductStock=int.Parse(this.txtProductStock.Text);
			decimal Price=decimal.Parse(this.txtPrice.Text);

			Maticsoft.Model.ProductInfo model=new Maticsoft.Model.ProductInfo();
			model.ProductImage=ProductImage;
			model.ProductType=ProductType;
			model.SeriesId=SeriesId;
			model.ProductName=ProductName;
			model.ProductGrade=ProductGrade;
			model.Color=Color;
			model.Material=Material;
			model.Voltage=Voltage;
			model.Power=Power;
			model.CutOut=CutOut;
			model.Size=Size;
			model.ProductStock=ProductStock;
			model.Price=Price;

			Maticsoft.BLL.ProductInfo bll=new Maticsoft.BLL.ProductInfo();
			bll.Add(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","add.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
